import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Scanner;

/**
 * Created by Administrator on 2016/10/19.
 */

public class main {
    public static void getARGB(int pixel){
        int alpha=(pixel>>24)&0xff;
        int red=(pixel>>16)&0xff;
        int green=(pixel>>8)&0xff;
        int blue=(pixel)&0xff;
        System.out.println("argb:"+alpha+","+red+","+green+","+blue);
    }
    public  static void main(String[] args)throws IOException{
        try{
            BufferedImage image= ImageIO.read(new File("src/mypicture.jpg"));
            int width=image.getWidth();
            int height=image.getHeight();
            int[] imageArray=new int[width*height];
            image.getRGB(0,0,width,height,imageArray,0,width);
            BufferedImage imageNew=new BufferedImage(width/2,height,BufferedImage.TYPE_INT_RGB);
            imageNew.setRGB(0,0,width/2,height,imageArray,0,width);
            File outFile=new File("src/newFlower.jpg");
            ImageIO.write(imageNew,"jpg",outFile);
            /*for(int i=0;i<width;i++){
                for(int j=0;j<height;j++){
                    getARGB(imageNew.getRGB(i,j));
                }
            }*/
            int select;
            int n;
            System.out.println("1、放大图像2、缩小图像");
            Scanner s=new Scanner(System.in);
            select=s.nextInt();
            switch (select){
                case  1: {System.out.println("请输入要放大的倍数");
                         n=s.nextInt();
                         BufferedImage imageAdd=new BufferedImage(n*width,n*height,BufferedImage.TYPE_INT_RGB);
                         int newwidth=imageAdd.getWidth();
                         int newheight=imageAdd.getHeight();
                         for(int i=0;i<newwidth;i++){
                             for(int j=0;j<newheight;j++){
                                 double p=i/n;
                                 double q=j/n;
                                 int x1=(int)p;
                                 int y1=(int)p;
                                 int x3=x1;int x4=x1+1;int x2=x1+1;int y2=y1;int y3=y1+1;int y4=y3;
                                 double one=(x2-p)*(y3-q)*image.getRGB(x1,y1);
                                 double two=(p-x1)*(y3-q)*image.getRGB(x2,y2);
                                 double three=(x2-p)*(q-y1)*image.getRGB(x3,y3);
                                 double four=(p-x1)*(q-y1)*image.getRGB(x4,y4);
                                 int result=(int)(one+two+three+four);
                                 imageAdd.setRGB(i,j,result);
                             }
                         }
                     File outFile1=new File("src/myaddpicture.jpg");
                     ImageIO.write(imageAdd,"jpg",outFile1);
                         break;
                }
                case 2:
                         break;
            }

        }
        catch (IOException e){
            e.printStackTrace();
        }
    }
}
